package com.jiyinit.web.core.business.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.business.dto.UserSalaryRequest;
import com.jiyinit.web.core.business.entity.TabCoreUserSalaryEntity;

/**
 * Created By Lichangqin
 * Date : 2019/1/8
 */
@Repository("core.tabCoreUserSalaryDao")
public class TabCoreUserSalaryDao {

	private String SQLID = "core.tabCoreUserSalaryDao.";

	@Autowired
	@Qualifier("core.MybatisDaoContext")
	private MybatisDaoContext mybatisDaoContext;
	
	/**
     * 多条件分页查询
     * @param request
     * @return
     */
    public PagingResult<TabCoreUserSalaryEntity> findForPage(UserSalaryRequest request) {
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID + "findForPage", TabCoreUserSalaryEntity.class, request.toMap(), pageBounds);
    }
    
    /**
     * id查询
     * @param id
     * @return
     */
    public TabCoreUserSalaryEntity findOne(Integer id){
    	return mybatisDaoContext.findOne(SQLID + "findOne", TabCoreUserSalaryEntity.class, id);
    }

    /**
     * 添加
     * @param
     * @return
     */
	public int add(List<TabCoreUserSalaryEntity> list) {
		return mybatisDaoContext.batchSave(SQLID+ "add", list);
	}

    /**
     * 添加
     * @param dataList
     * @return
     */
	public int insertList(List<TabCoreUserSalaryEntity> dataList) {
        SqlSessionTemplate sqlSessionTemplate = mybatisDaoContext.getWriteSqlSessionTemplate();
		return sqlSessionTemplate.insert(SQLID+ "insertList", dataList);
	}
	
	/**
     * 修改
     * @param entity
     * @return
     */
	public int update(TabCoreUserSalaryEntity entity) {
		return mybatisDaoContext.update(SQLID+ "update", entity);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	public int delete(Integer id){
		Map<String, Object> map = new HashMap<>();
		map.put("id", id);
		return mybatisDaoContext.update(SQLID+ "delete", map);
	}
	
}
